﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using INHSStudentRegistration;

namespace IrisanNHS
{
    public partial class Form1 : Form
    {
        MainForm parent;

        DataTable DT = new DataTable();

        DataBaseConnection DBC = new DataBaseConnection();
        StudentInformation student = new StudentInformation();
        
        public Form1(MainForm p)
        {
            InitializeComponent();
            parent = p;
            this.Load += new EventHandler(Form1_Load);
            btnSubmit.Click += new EventHandler(btnSubmit_Click);
            btnAdd.Click += new EventHandler(btnAdd_Click);
        }

        private void register()
        {
            try
            {
                student.date = dtpickerdenrolled.Text;
                student.year = txtsyear.Text;
                student.schoolsstatus = comboBoxsstatus.Text;
                student.lrn = txtLRN.Text;
                student.name = txtsname.Text;
                student.sex = comboBoxsex.Text;
                student.dateofbirth = dtpickerdobirth.Text;
                student.placeofbirth = txtpobirth.Text;
                student.religion = txtreligion.Text;
                student.preaddress = txtpreaddress.Text;
                student.contact1 = txtcno1.Text;
                student.preaddress = txtpreaddress.Text;
                student.contact2 = txtcno2.Text;
                student.fathersname = txtfather.Text;
                student.occupation1 = txtoccupation1.Text;
                student.contact3 = txtcno3.Text;
                student.mothersname = txtmother.Text;
                student.occupation2 = txtoccupation2.Text;
                student.contact4 = txtcno4.Text;
                student.guardiansname = txtguardiansname.Text;
                student.relation1 = txtrelation1.Text;
                student.incaseofemergency = txtptcicoemergency.Text;
                student.relation2 = txtrelation2.Text;
                student.address = txtaddress.Text;
                student.contact5 = txtcno5.Text;
                student.schoollastattended = txtsla.Text;
                student.schooladdress = txtsaddress.Text;
                student.noofchildreninthefamily = txtnoocitfamily.Text;
                student.noiflivinginyourhouse = txtnooifliyhouse.Text;
                student.fps = comboBoxfps.Text;

                DBC.Register_Student(student);
                MessageBox.Show("Successfully Saved");
            }
            catch (Exception)
            {
                MessageBox.Show("Complete the Registration");
                return;
            }
            

        }

        void btnAdd_Click(object sender, EventArgs e)
        {
            
        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            register();

            dtpickerdenrolled.Text = "";
            txtsyear.Text = "";
            comboBoxsstatus.Text = "";
            txtLRN.Text = "";
            txtsname.Text = "";
            comboBoxsex.Text = "";
            dtpickerdobirth.Text = "";
            txtpobirth.Text = "";
            txtreligion.Text = "";
            txtpreaddress.Text = "";
            txtcno1.Text = "";
            txtpreaddress.Text = "";
            txtcno2.Text = "";
            txtfather.Text = "";
            txtoccupation1.Text = "";
            txtcno3.Text = "";
            txtmother.Text = "";
            txtoccupation2.Text = "";
            txtcno4.Text = "";
            txtguardiansname.Text = "";
            txtrelation1.Text = "";
            txtptcicoemergency.Text = "";
            txtrelation2.Text = "";
            txtaddress.Text = "";
            txtcno5.Text = "";
            txtsla.Text = "";
            txtsaddress.Text = "";
            txtnoocitfamily.Text = "";
            txtnooifliyhouse.Text = "";
            comboBoxfps.Text = "";
        }

        void Form1_Load(object sender, EventArgs e)
        {
            DBC.DBConnection();
            DBC.MyQuery("SELECT * FROM irisansrtable");
            DBC.Close();
        }

        void School_Status()
        {
            comboBoxsstatus.Items.Add("OLD STUDENT");
            comboBoxsstatus.Items.Add("NEW STUDENT");
            comboBoxsstatus.Items.Add("TRANSFEREE");
        }

        void Sex()
        {
            comboBoxsex.Items.Add("MALE");
            comboBoxsex.Items.Add("FEMALE");
        }

        void Forpis()
        {
            comboBoxfps.Items.Add("YES");
            comboBoxfps.Items.Add("NO");
        }

       
    }
}
